package com.jspgou.cms.manager.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jspgou.common.hibernate3.Updater;
import com.jspgou.common.page.Pagination;
import com.jspgou.cms.dao.ShopTuijanproductDao;
import com.jspgou.cms.entity.Category;
import com.jspgou.cms.entity.ShopTuijanproduct;
import com.jspgou.cms.entity.ShopTuijian;
import com.jspgou.cms.entity.Product;
import com.jspgou.cms.manager.ShopTuijanproductMng;

@Service
@Transactional
public class ShopTuijanproductMngImpl implements ShopTuijanproductMng {
	@Transactional(readOnly = true)
	public Pagination getPage(int pageNo, int pageSize) {
		Pagination page = dao.getPage(pageNo, pageSize);
		return page;
	}

	@Transactional(readOnly = true)
	public ShopTuijanproduct findById(Long id) {
		ShopTuijanproduct entity = dao.findById(id);
		return entity;
	}

	public ShopTuijanproduct save(ShopTuijanproduct bean) {
		dao.save(bean);
		
		return bean;
	}

	public ShopTuijanproduct update(ShopTuijanproduct bean) {
		Updater<ShopTuijanproduct> updater = new Updater<ShopTuijanproduct>(bean);
		ShopTuijanproduct entity = dao.updateByUpdater(updater);
		return entity;
	}

	public ShopTuijanproduct deleteById(Long id) {
		ShopTuijanproduct bean = dao.deleteById(id);
		return bean;
	}
	
	public ShopTuijanproduct[] deleteByIds(Long[] ids) {
		ShopTuijanproduct[] beans = new ShopTuijanproduct[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	private ShopTuijanproductDao dao;

	@Autowired
	public void setDao(ShopTuijanproductDao dao) {
		this.dao = dao;
	}

	public List<ShopTuijanproduct> getShopTuijanproducts(Product product,
			ShopTuijian tuijian) {
		
		return dao.getShopTuijanproducts(product, tuijian);
	}

	public Pagination getBytuijian(Long id,int pageNo, int pageSize) {
		
		return dao.getBytuijian(id,pageNo, pageSize);
	}
	
	public ShopTuijanproduct[] updateOrder(Long[] ids, Integer[] priority) {
		
		ShopTuijanproduct[] beans = new ShopTuijanproduct[ids.length];
		for (int i = 0, len = ids.length; i < len; i++) {
			beans[i] = findById(ids[i]);
			beans[i].setTjorder(priority[i]);
		}
		return beans;
	}

	public List<ShopTuijanproduct> getList(Long id, int count) {
		
		return dao.getList(id, count);
	}
}